<template>
	<div>
        <van-nav-bar
			title="个人信息"
			left-arrow
			left-text="返回"
			fixed
			@click-left="goBack"
		/>
        <personInfoField v-if="isChange" ref="personInfo" @toParent="changeSucceed"></personInfoField>
        <personInfoCell v-else></personInfoCell>
        <div style="margin: 16px;">
				<van-button round block type="info" @click="changePersonInfo">{{changePersonInfoMsg}}</van-button>
		</div>
	</div>
</template>

<script>
    // import { Toast } from 'vant';
	// import {changePsw} from '../../api/person.js';    
    import  personInfoCell  from '../../components/personInfoCell.vue';
    import  personInfoField  from '../../components/personInfoField.vue';
    
	export default {
		name: 'personInfo',
		data() {
			return {
                isChange: false, // 是否在修改状态  0 不修改，展示个人信息   1  修改
			}
		},
        components: {
            personInfoField,
            personInfoCell
        },
        computed: {
            changePersonInfoMsg() {
                return this.isChange?'保存修改':'修改'
            }
        },
		methods:{
			
			goBack() {
                if(this.isChange) {
                    this.isChange = !this.isChange;
                } else {
                    this.$router.push({
                        name: 'home',
                        params: {
                            active: 1
                        }
                    })
                }
				
			},
            changePersonInfo() {
                if(this.isChange) {                    
                    this.$refs.personInfo.onChangePersonInfo();
                    
                } else 
                this.isChange = !this.isChange;

                
            },
            changeSucceed(msg) {
                if(msg === "changeSucceed") {
                    this.isChange =!this.isChange;
                    console.log('修改个人信息成功');
                }
            }
		}
	}
</script>

<style>
</style>
